﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace MessageService.UserService
{
    public partial class User
    {
        public static explicit operator DataAccessService.User(UserService.User oldUser)
        {
            DataAccessService.User newUser = new DataAccessService.User();
            foreach (var oldUserProperty in oldUser.GetType().GetProperties())
            {
                string propertyName = oldUserProperty.Name;
                object propertyValue = oldUserProperty.GetValue(oldUser,null);
                var newProperty = newUser.GetType().GetProperty(propertyName);
                if(newProperty!=null)
                    try { newProperty.SetValue(newUser, propertyValue, null); }
                    catch (Exception) { }
            }
            return newUser;
        }
    }
}
